package com.lun.easy;

public class MaxConsecutiveOnes {
	// 我写的
	public int findMaxConsecutiveOnes(int[] nums) {
		int max = 0, count = 0;
		for (int num : nums) {
			if (num == 0) {
				count = 0;
			} else {
				if (++count > max) {
					max = count;
				}
			}
		}
		return max;
	}

	// 别人的
	public int findMaxConsecutiveOnes2(int[] nums) {
		int maxHere = 0, max = 0;
		for (int n : nums)
			max = Math.max(max, maxHere = n == 0 ? 0 : maxHere + 1);
		return max;
	}
}
